package com.monster.security.config;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * 自定义sessionid
 * @author kuang
 */
public class HeaderHttpSessionIdResolver extends org.springframework.session.web.http.HeaderHttpSessionIdResolver {
    String headerName;
    /**
     * The name of the header to obtain the session id from.
     *
     * @param headerName the name of the header to obtain the session id from.
     */
    public HeaderHttpSessionIdResolver(String headerName) {
        super(headerName);
        this.headerName = headerName;
    }

    @Override
    public void setSessionId(HttpServletRequest request, HttpServletResponse response, String sessionId) {
        super.setSessionId(request, response, sessionId);
        String accessControlExposeHeaders = response.getHeader("Access-Control-Expose-Headers");
        response.setHeader("Access-Control-Expose-Headers", accessControlExposeHeaders + "," + headerName);
    }
}
